package com.xywy.tangandroid.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.xywy.tangandroid.R;
import com.xywy.tangandroid.base.BasicAdapter;
import com.xywy.tangandroid.receiver.BroadcastAction;
import com.xywy.tangandroid.util.Constant;

public class ProvinceAdapter extends BasicAdapter<String> {
	private Context context;
	private List<String> list1;
	private LayoutInflater inflater;
	private SetProvince setvalue;

	public ProvinceAdapter(Context context, List<String> list1) {
		super(context, list1);
		this.context = context;
		this.list1 = list;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		viewholder holder = null;
		if (convertView == null) {
			holder = new viewholder();
			convertView = inflater.inflate(R.layout.item_popwindow, null);
			holder.province = (TextView) convertView
					.findViewById(R.id.province);
			convertView.setTag(holder);
		} else {
			
			holder = (viewholder) convertView.getTag();
		}

		final String provincename = list.get(position);
		holder.province.setText(provincename);

		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				setvalue.setprovince().setText(provincename);
				PopupWindow popupWindow = setvalue.popwindowNeedDismiss();
				if (popupWindow != null && popupWindow.isShowing()) {
					popupWindow.dismiss();
					Constant.flag = true;
				}
				if("不限".equals(provincename))
				 Constant.PPROVINCE="";
				else
					Constant.PPROVINCE=provincename;
				 Intent it = new Intent(BroadcastAction.ACTION_SEND_EXPERT_LIST_REQUESTION);  
	             context.sendBroadcast(it);
			}
		});
		return convertView;
	}

	public void setView(SetProvince province) {
		this.setvalue = province;
	}

	//
	public interface SetProvince {
		public TextView setprovince();

		public PopupWindow popwindowNeedDismiss();
	}

	private class viewholder {
		TextView province;
	}
}
